package edu.hunau.recommend.common;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

/**
 * @author name
 * @creater 2022-09-09-11:26
 */
public class CommonUtils {

    public static String processErrorMessage(BindingResult bindingResult){
        if (!bindingResult.hasErrors()){
            return "";
        }
        List<FieldError> fieldErrors = bindingResult.getFieldErrors();
        StringBuilder sb = new StringBuilder();
        fieldErrors.forEach(e-> sb.append(e.getDefaultMessage() +",") );
        return sb.substring(0,sb.length()-1);
    }
}
